package com.example.mqspring.rabiitmqbasicleverone.rabbitmqDirectRoutkey;

import com.example.mqspring.utils.RabbitMqUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/**
 * 接收消息 根据routkey 和交换机绑定的队列
 */
public class MainClassConsumer {

    private static String myExchangge = "bobo-exchange-direct";
    private static String routingkey = "BOBO_DIRECT_MESSAGE";
    private static String queue = "mydirectqueue";
    public static void main(String[] args) {
        Connection connection = RabbitMqUtil.createConnection();
        Channel channel = null;
        try {
            channel = connection.createChannel();
            Consumer consumer = new Consumer(channel);
            channel = consumer.declareConsumer(queue,channel, myExchangge, routingkey);
            String s = channel.basicConsume(queue, true, consumer);
            channel.basicCancel(s);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
//                channel.close();
//                connection.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }
}
